package com.leyou.page.controller;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    /**
     * 通过spuId获得商品详情页面数据
     * 跳转到item.html页面
     * @param spuId
     * @param model
     * @return
     */
    @GetMapping("item/{spuId}.html")
    public String loadData(@PathVariable("spuId")Long spuId, Model model){

        // 查询并存入模型数据，因为数据较多，直接存入一个map
        model.addAllAttributes(this.pageService.loadData(spuId));

        return "item";
    }


}
